home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / dtype / cdt_39_10.lha / cdt / source / RCS / classbase.c,v < prev    next >
Text File  |  1995-06-04  |  3KB  |  166 lines

  1. head    39.1;
  2. access;
  3. symbols
  4.     V39_10:39.1
  5.     c3910:39.1
  6.     V39_9:39.1;
  7. locks; strict;
  8. comment    @** @;
  9.  
  10.  
  11. 39.1
  12. date    95.05.10.14.59.25;    author StRuppert;    state Exp;
  13. branches;
  14. next    ;
  15.  
  16.  
  17. desc
  18. @initial
  19. @
  20.  
  21.  
  22. 39.1
  23. log
  24. @*** empty log    message    ***
  25. @
  26. text
  27. @/*
  28. ** $PROJECT: c.datatype
  29. **
  30. ** $VER: classbase.c 39.1 (06.03.95)
  31. **
  32. ** by
  33. **
  34. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  35. **
  36. ** (C) Copyright 1995
  37. ** All Rights Reserved !
  38. **
  39. ** $HISTORY:
  40. **
  41. ** 06.03.95 : 039.001 : initial
  42. */
  43.  
  44. #include "classbase.h"
  45.  
  46. LibCall Class *ENGINE (REGA6 struct ClassBase *cb)
  47. {
  48.    return(cb->cb_Class);
  49. }
  50.  
  51. LibCall struct Library *LibInit (REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct Library * sysbase)
  52. {
  53.    cb->cb_SegList = seglist;
  54.    cb->cb_SysBase = sysbase;
  55.    InitSemaphore (&cb->cb_Lock);
  56.  
  57.    DB(("c.datatype init !\n"));
  58.  
  59.    if(cb->cb_SysBase->lib_Version >= 39)
  60.    {
  61.       cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
  62.       cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
  63.       cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
  64.       cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
  65.    } else
  66.       cb = NULL;
  67.  
  68.   return((struct Library *) cb);
  69. }
  70.  
  71. LibCall LONG LibOpen (REGA6 struct ClassBase *cb)
  72. {
  73.    LONG retval = (LONG) cb;
  74.  
  75.    ObtainSemaphore (&cb->cb_Lock);
  76.  
  77.    /* Use an internal use counter */
  78.    cb->cb_Lib.lib_OpenCnt++;
  79.    cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  80.  
  81.    if(cb->cb_Lib.lib_OpenCnt == 1 && cb->cb_Class == NULL)
  82.    {
  83.       retval = (LONG) NULL;
  84.  
  85.       if((cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39)))
  86.          if((cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39)))
  87.             if((cb->cb_SuperClassBase = OpenLibrary(SUPERCLASSDATATYPE,39)))
  88.                if((cb->cb_Class = initClass(cb)))
  89.                   retval = (LONG) cb;
  90.  
  91.       if(!retval)
  92.       {
  93.          if(cb->cb_IFFParseBase)
  94.          {
  95.             CloseLibrary(cb->cb_IFFParseBase);
  96.             cb->cb_IFFParseBase = NULL;
  97.          }
  98.  
  99.          if(cb->cb_DataTypesBase)
  100.          {
  101.             CloseLibrary(cb->cb_DataTypesBase);
  102.             cb->cb_DataTypesBase = NULL;
  103.          }
  104.  
  105.          if(cb->cb_SuperClassBase)
  106.          {
  107.             CloseLibrary(cb->cb_SuperClassBase);
  108.             cb->cb_SuperClassBase = NULL;
  109.          }
  110.  
  111.          cb->cb_Lib.lib_OpenCnt--;
  112.       }
  113.    }
  114.  
  115.    ReleaseSemaphore (&cb->cb_Lock);
  116.  
  117.    return (retval);
  118. }
  119.  
  120. LibCall LONG LibClose (REGA6 struct ClassBase *cb)
  121. {
  122.    LONG retval = NULL;
  123.  
  124.    ObtainSemaphore (&cb->cb_Lock);
  125.  
  126.    if (cb->cb_Lib.lib_OpenCnt)
  127.       cb->cb_Lib.lib_OpenCnt--;
  128.  
  129.    if((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  130.    {
  131.       if(FreeClass (cb->cb_Class))
  132.       {
  133.          cb->cb_Class = NULL;
  134.          CloseLibrary(cb->cb_SuperClassBase);
  135.          CloseLibrary(cb->cb_DataTypesBase);
  136.          CloseLibrary(cb->cb_IFFParseBase);
  137.       } else
  138.          cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  139.    }
  140.  
  141.    if(cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  142.        retval = LibExpunge (cb);
  143.  
  144.    ReleaseSemaphore (&cb->cb_Lock);
  145.  
  146.    return (retval);
  147. }
  148.  
  149. LibCall LONG LibExpunge(REGA6 struct ClassBase *cb)
  150. {
  151.    BPTR seg = cb->cb_SegList;
  152.  
  153.    Remove((struct Node *) cb);
  154.  
  155.    CloseLibrary(cb->cb_UtilityBase);
  156.    CloseLibrary(cb->cb_DOSBase);
  157.    CloseLibrary(cb->cb_GfxBase);
  158.    CloseLibrary(cb->cb_IntuitionBase);
  159.  
  160.    FreeMem((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  161.  
  162.    return((LONG) seg);
  163. }
  164.  
  165. @
  166.